package com.lm.scau.dyb.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lm.scau.dyb.R;
import com.lm.scau.dyb.activity.base.BaseActivity;
import com.lm.scau.dyb.bean.Movie;
import com.lm.scau.dyb.utils.ImageLoaderUtil;
import com.lm.scau.dyb.utils.ViewHolderUtils;

import java.util.List;

/**
 * Function:
 * auth：liming on 2016/9/1 10:56
 * mail：liming@wxchina.com
 */
public class MovieAdapter extends BaseAdapter {
    private BaseActivity activity;
    private List<Movie> movieList;

    public MovieAdapter(BaseActivity activity, List<Movie> movieList) {
        this.activity = activity;
        this.movieList = movieList;
    }

    @Override
    public int getCount() {
        return movieList.size();
    }

    @Override
    public Movie getItem(int position) {
        return movieList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (null == convertView) {
            convertView = LayoutInflater.from(activity).inflate(R.layout.item_movie, parent, false);
        }
        TextView movieName = ViewHolderUtils.get(convertView, R.id.movie_name);
        TextView movieRole = ViewHolderUtils.get(convertView, R.id.movie_role);
        TextView movieInfo = ViewHolderUtils.get(convertView, R.id.movie_text);
        ImageView movieIcon = ViewHolderUtils.get(convertView, R.id.movie_icon);
        Movie movie = getItem(position);
        movieName.setText(movie.getMovieName());
        movieRole.setText(movie.getMovieRole());
        movieInfo.setText(movie.getMovieSummary());
        // ImageLoaderUtil.getImageView(movie.getMoviePhurl(),movieIcon);
        return convertView;
    }

    public int getLastRowId() {
        return movieList.get(movieList.size() - 1).getMoveiID();
    }
}
